#include <gtest/gtest.h>
#include <string>

using namespace ::std;

// 暴力法
// 耍赖解法
// KMP算法

// 暴力法
// class Solution {
// public:
//     int strStr(string haystack, string needle) {
// 		if(needle.size() == 0) return 0;
// 		int i, j, k;
// 		for(i = 0; i < haystack.size(); ++i) {
// 			for(j = i, k = 0; j < haystack.size() && k < needle.size() && haystack[j] == needle[k]; ++j, ++k)
// 				;
// 			if(k == needle.size()) return i;
// 		}
// 		return -1;
//     }
// };

// 耍赖解法
class Solution {
public:
    int strStr(string haystack, string needle) {
		return haystack.find(needle);
    }
};

class StrStrCheck : public ::testing::Test {
public:
	class Solution solution;
};

TEST_F(StrStrCheck, testStrStr_1) {
	string haystack = "hello", needle = "ll";
	EXPECT_TRUE(2 == solution.strStr(haystack, needle));
}

TEST_F(StrStrCheck, testStrStr_2) {
	string haystack = "aaaaa", needle = "bba";
	EXPECT_TRUE(-1 == solution.strStr(haystack, needle));
}

TEST_F(StrStrCheck, testStrStr_3) {
	string haystack = "", needle = "";
	EXPECT_TRUE(0 == solution.strStr(haystack, needle));
}

int main() {
	::testing::InitGoogleTest();
	return RUN_ALL_TESTS();
}